package com.rfsp.mcp.controller.base;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.rfsp.common.log.TrcMsg;
import com.rfsp.mcp.pojo.sdto.MiPaySDTO;
import com.rfsp.mcp.pojo.vo.MiPayLogVO;
import com.rfsp.mcp.pojo.vo.MiPayVO;
import com.rfsp.mcp.service.PayLogService;
import com.rfsp.mcp.service.PayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller("BasePayLogController")
@RequestMapping("/base/payLog")
public class BasePayLogController extends BaseController{

    public Logger logger = LoggerFactory.getLogger(BasePayLogController.class);

    @Autowired
    PayLogService service;

    @Autowired
    PayService payService;

    @GetMapping("/detail")
    public String detail(ModelMap model,Long id ,String aid) throws JsonProcessingException {
        logger.info(TrcMsg.getMsg(TrcMsg.METHOD_BEGIN, "BasePayLogController.detail"));

        MiPayLogVO vo=service.getById(id);
        if(!vo.getAid().equals(aid)){
            return this.errorAidNotMatch(model);
        }
        MiPaySDTO paySdto=new MiPaySDTO();
        paySdto.setPayLogId(id);
        List<MiPayVO> payVoList=payService.get(paySdto);
        vo.setPayList(payVoList);
        payService.combo(payVoList);
        model.put("vo",vo);

        logger.info(TrcMsg.getMsg(TrcMsg.METHOD_END, "BasePayLogController.detail"));
        return "base/payLog/detail";
    }
}
